package com.example.activity_service.controller;


import com.example.activity_service.service.JPQueryService;
import com.example.activity_service.vo.Admin;
import com.example.activity_service.vo.Dui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@ResponseBody
public class JPController {

    @Autowired
    JPQueryService user;


    @RequestMapping("/activity/admin")
    public List<Admin> gethuodong(@RequestParam(value = "feiye",required = false) String feiye){

        int totalRecord=user.totalRecord();//总记录数量
        int pageSize=4;//每页查的条数
        int totalPageNum = (totalRecord +pageSize - 1) / pageSize;

        int ye=0;
        if (feiye!=null){
             ye=Integer.parseInt(feiye) ;
        }
        List<Admin> xxx=user.admin(ye);
        xxx.get(0).setTotalPageNum(totalPageNum);
        return xxx;
    }
    @RequestMapping("/activity/hongbaoyu")
    public String addhongbaoyu(@RequestParam(value = "id",required = false) String id,@RequestParam(value = "qian",required = false) String qian){
        user.addhongbao(id,qian);

        return "true";
    }
    @RequestMapping("/activity/adadmi")
    public String adadmi(@RequestParam("name")String name,@RequestParam("dizi")String dizi){
        user.adadmi(name,dizi);
        return "true";
    }
    @RequestMapping("/activity/adxiu")
    public String adxiu(@RequestParam("id")String id,@RequestParam("zt")String zt){
    user.adxiu(id,zt);
        return "true";
    }
    @RequestMapping("/activity/schuo")
    public String schuo(@RequestParam("id")String id){
      int x=  user.schuo(id);
      if (x>0){
          return "true";
      }
        return "false";
    }
    @RequestMapping("/activity/duica")
    public List<Dui> cxduihuan(@RequestParam(value = "fen",required = false) String feiye){
        int totalRecord=user.catotalRecord();//总记录数量
        int pageSize=4;//每页查的条数
        int totalPageNum = (totalRecord +pageSize - 1) / pageSize;
        int ye=Integer.parseInt(feiye);
    List<Dui> list=user.duica(ye);
    list.get(0).setTotalPageNum(totalPageNum);
        return list;
    }
    @RequestMapping("/activity/adddui")
    public String adddui(Dui dui){
        user.adddui(dui);
        return "true";
    }
    @RequestMapping("/activity/xiudui")
    public String xiudui(Dui dui){
        System.out.println(222);
        user.xiudui(dui);
        return "true";
    }
    @RequestMapping("/activity/scdui")
    public String scdui(@RequestParam("id")String id){
        user.scdui(id);
        return "true";
    }

}
